<!--
 * @author  dumeng
 活动花絮预览
-->
<template>
  <div class="tidbits-preview">
    <el-dialog
      v-el-drag-dialog
      :close-on-click-modal="false"
      :visible.sync="state"
      title="预览"
      width="375px"
      center
      :before-close="handleCancel"
    >
      <div v-loading="previewLoading" class="preview-container">
        <div class="content" :class="{'b0': detail.commentState === 0 || detail.commentState === 1}">
          <div class="title">
            {{ detail.tidbitsTitle||'' }}
          </div>
          <div class="user-info-content">
            <div class="left-content">
              <el-image
                class="item-user-icon"
                :src="view + detail.userView"
                :fit="cover"
              >
                <div slot="error" class="image-slot">
                  <i class="el-icon-picture-outline" />
                </div>
              </el-image>
              <div>
                <p>{{ detail.userRealName }}</p>
                <p>{{ detail.crtTime.length > 10 ? detail.crtTime.substring(0, 10) : detail.crtTime }}</p>
              </div>
            </div>

          </div>
          <div class="data">
            <template v-if="detail.video && detail.video.split(',').length > 0">
              <div v-for="item in detail.video.split(',')" :key="item">
                <video :src="view + item" controls />
              </div>
            </template>
            <template v-if="detail.image && detail.image.split(',').length > 0">
              <div v-for="item in detail.image.split(',')" :key="item">
                <img :src="view + item" alt="">
              </div>
            </template>
            <p v-if="detail.tidbitsContent" class="news-text desc-wrap" v-html="detail.tidbitsContent" />
          </div>

        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button style="padding: 8px 30px;" @click="handleCancel()">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { get } from '../api/tidbits'
import elDragDialog from '@/directive/el-drag-dialog' // base on element-ui
export default {
  name: 'TidbitsPreview',
  directives: { elDragDialog },
  props: {
    id: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      detail: {},
      state: true,
      previewLoading: false,
      view: '/API-DOCUMENT/document/file/download?id='
    }
  },
  created() {
    this.getData()
  },
  methods: {
    /**
     * 根编辑回显
     */
    getData() {
      this.previewLoading = true
      return new Promise((resolve, reject) => {
        get({ id: this.id }).then(res => {
          this.previewLoading = false
          this.detail = res.data.data
        }).catch(error => {
          this.previewLoading = false
          reject(error)
        })
      })
    },
    handleCancel() {
      this.$emit('closeSet')
    }
  }
}
</script>

<style lang="scss">
.tidbits-preview {
  position: relative;

  .preview-container {
    height: 80vh;
    position: relative;
  }

  .content {
    padding: 20px 0;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    top: 0;
    overflow-y: auto;

    .title {
      font-size: 20px;
      font-family: PingFang SC Medium, PingFang SC Medium-Medium;
      font-weight: bold;
      text-align: left;
      color: #333333;
    }

    .user-info-content {
      margin-top: 18px;
      display: flex;
      align-items: center;
      justify-content: space-between;

      .left-content {
        display: flex;
        align-items: center;

        .item-user-icon {
          margin-right: 5px;
          width: 30px;
          height:  30px;
          border-radius:  30px;
          background-color: #e5e5e5;
        }

        > div {
          p {
            &:first-child {
              font-size: 12px;
              font-weight: bold;
              text-align: left;
              color: #333333;
            }

            &:last-child {
              margin-top: 2px;
              font-size: 9px;
              font-weight: 400;
              text-align: left;
              color: #999;
            }
          }
        }
      }

      .like {
        position: relative;
        font-size: 12px;
        font-weight: bold;
        text-align: left;
        color: #999999;

        &.select {
          &:before {
            background: url("../images/ic_like.png") no-repeat center;
            background-size: 100% 100%;
          }
        }

        &:before {
          position: absolute;
          top: 50%;
          left: -20px;
          margin-top: -7px;
          vertical-align: baseline;
          display: inline-block;
          content: '';
          width: 15px;
          height:15px;
          background: url("../images/ic_comment.png") no-repeat center;
          background-size: 100% 100%;
        }
      }

    }
    .data {
      margin-top: 7px;

      img, video {
        width: 100%;
      }

      .explain {
        text-align: center;
      }
    }

    .file {
      margin: 12px 0;
      width: 100%;
      background: linear-gradient(#fff3ed 0%, #ffeadf 100%);
      border-radius: 16px;
      padding: 10px;
      padding-top: 0;

      .row1 {
        display: flex;
        height: 40px;
        font-family: PingFang SC Medium, PingFang SC Medium-Medium;
        line-height: 40px;
        border-bottom: 1px dotted #f5c7ac;

        .left {
          flex: 1;
          text-align: left;
          font-size: 14px;
          font-weight: 500;
          color: #333333;
        }

        .right {
          flex: 1;
          text-align: right;

          .btn {
            display: inline-block;
            width: 58px;
            text-align: center;
            height: 24px;
            border-radius: 12px;
            line-height: 24px;
            color: #fff;
            background: #eb523c;
          }
        }
      }

      .fitem {
        margin-top: 10px;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
        word-break: break-all;

        img {
          width: 24px;
          height: 24px;
          vertical-align: middle;
        }

        span {
          margin-left: 10px;
          font-size: 12px;
          color: #666666;
        }
      }
    }

    .right-bottom {
      margin-top: 20px;
      height: 30px;
      font-family: PingFang SC Regular, PingFang SC Regular-Regular;
      font-weight: 400;
      text-align: left;
      color: #999999;

      .author {
        text-align: right;
        font-size: 13px;
      }
    }

    .news-text {
      font-size: 15px;

      video, audio, img {
        display: block;
        max-width: 100% !important;
        height: auto !important;
      }
    }

    .common-container {
      h4 {
        font-size: 14px;
        color: #333;
      }

      .comment-con {
        position: relative;
        min-height: 150px;

        .comment-item {
          display: flex;
          margin-bottom: 30px;

          &:last-child {
            margin-bottom: 10px;
          }

          & > img {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            margin-right: 10px;
            flex: 0 0 auto;
          }

          .comment-item-right {
            .comment-item-right-content {
              display: flex;
              justify-content: space-between;

              .comment-name {
                font-size: 14px;
                font-family: PingFangSC-Regular;
                font-weight: bold;
                color: rgba(51, 51, 51, 1);
                line-height: 18px;
              }
            }

            .comment-time {
              display: flex;
              align-items: center;
              font-size: 12px;
              font-family: PingFangSC-Regular;
              font-weight: 400;
              color: #999;
              line-height: 18px;

              .reply {
                margin-left: 10px;
                color: #666;
              }
            }

            .comment-content {
              width: 293px;
              font-size: 14px;
              font-family: PingFangSC-Regular;
              font-weight: 400;
              color: rgba(51, 51, 51, 1);
              line-height: 21px;
              margin-top: 5px;
              word-wrap: break-word;
            }

            .comment-img {
              display: flex;
              margin: 5px 0;

              .van-image {
                margin-left: 5px;

                &:first-child {
                  margin-left: 0;
                }

                img {
                  width: 82px;
                  height: 82px;
                  border-radius: 6px;
                }
              }
            }

            .reply-content {
              width: 100%;
              background-color: #fafafa;
              padding: 5px 10px;
              margin-top: 5px;

              li {
                margin-bottom: 20px;
                position: relative;

                &:last-child {
                  margin-bottom: 0;

                  &:after {
                    display: none;
                  }
                }

                &:after {
                  left: 0;
                  right: 0;
                  width: auto;
                  height: 1px;
                  position: absolute;
                  z-index: 0;
                  bottom: -10px;
                  content: "";
                  background-image: -webkit-gradient(
                          linear,
                          left bottom,
                          left top,
                          color-stop(50%, #ececec),
                          color-stop(0, transparent)
                  );
                  background-image: linear-gradient(0deg, #ececec 50%, transparent 0);
                }
              }

              .reply-info {
                display: flex;
                align-items: center;
                flex-wrap: wrap;

                .replyer {
                  color: #9E9E9E;

                  span {
                    color: #666;
                  }
                }

                .reply-info {
                  color: #333;
                }
              }

              .reply-img {
                display: flex;
                margin: 7px 0;

                .van-image {
                  margin-left: 5px;

                  &:first-child {
                    margin-left: 0;
                  }

                  img {
                    width: 82px;
                    height: 82px;
                    border-radius: 6px;
                  }
                }

              }

              .reply-time {
                color: #999;
                font-size: 12px;
                margin-top: 4px;

                .reply {
                  margin-left: 10px;
                  color: #666;
                }
              }

              .get-son {
                text-align: center;
                @include font-color($mainColor)
              }
            }
          }
        }
      }
    }
  }

  .menu {
    position: absolute;
    right: 15px;
    bottom: 155px;
    width: 50px;
    height: 225px;
    z-index: 9;

    .menuItem {
      margin: 10px auto;
      width: 47px;
      height: 47px;
      border-radius: 50%;
      background: rgba(0, 0, 0, 0.75);
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;

      .icon {
        width: 16px;
        height: 16px;
        flex: 0 0 auto;
      }

      .num {
        font-size: 10px;
        font-family: PingFang SC Regular, PingFang SC Regular-Regular;
        font-weight: 400;
        color: #ffffff;
      }
    }
  }
}
</style>
